From e8c790c70c319ada47554e4e089b896e92186e73 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Fri, 7 Oct 2005 11:16:28 +0100 Subject: [PATCH] The attached fixes a few things to make the blkfront and netfront drivers better follow the Linux driver model. Changes include: * Rename xenbus_register functions to more closely match what's used with other buses. Adjust callers * There's no need to wait for the first vbd of vif and do a timeout if they fail, device probing is async * Add sysfs attributes for examining type and nodename * Set device of gendisk so /sys/block/foo/device points to the right place * Set device of net_device so that /sys/class/net/foo/device points to the right place Signed-off-by: Jeremy Katz --- .../drivers/xen/blkfront/blkfront.c | 30 +------------- .../drivers/xen/blkfront/vbd.c | 1 + .../drivers/xen/netfront/netfront.c | 40 +++---------------- .../drivers/xen/tpmfront/tpmfront.c | 2 +- .../drivers/xen/xenbus/xenbus_probe.c | 28 ++++++++++--- linux-2.6-xen-sparse/include/asm-xen/xenbus.h | 2 +- 6 files changed, 31 insertions(+), 72 deletions(-) diff --git a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c index c30ab0f8b0..0f4f6d0bac 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c @@ -53,8 +53,6 @@ #define BLKIF_STATE_DISCONNECTED 0 #define BLKIF_STATE_CONNECTED 1 -static unsigned int blkif_state = BLKIF_STATE_DISCONNECTED; - #define MAXIMUM_OUTSTANDING_BLOCK_REQS \ (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLKIF_RING_SIZE) #define GRANT_INVALID_REF 0 @@ -472,8 +470,6 @@ static void watch_for_status(struct xenbus_watch *watch, const char *node) info->connected = BLKIF_STATE_CONNECTED; xlvbd_add(sectors, info->vdevice, binfo, sector_size, info); - blkif_state = BLKIF_STATE_CONNECTED; - xenbus_dev_ok(info->xbdev); /* Kick pending requests. */ @@ -716,29 +712,7 @@ static struct xenbus_driver blkfront = { static void __init init_blk_xenbus(void) { - xenbus_register_device(&blkfront); -} - -static int wait_for_blkif(void) -{ - int err = 0; - int i; - - /* - * We should figure out how many and which devices we need to - * proceed and only wait for those. For now, continue once the - * first device is around. - */ - for (i = 0; blkif_state != BLKIF_STATE_CONNECTED && (i < 10*HZ); i++) { - set_current_state(TASK_INTERRUPTIBLE); - schedule_timeout(1); - } - - if (blkif_state != BLKIF_STATE_CONNECTED) { - WPRINTK("Timeout connecting to device!\n"); - err = -ENOSYS; - } - return err; + xenbus_register_driver(&blkfront); } static int __init xlblk_init(void) @@ -751,8 +725,6 @@ static int __init xlblk_init(void) init_blk_xenbus(); - wait_for_blkif(); - return 0; } diff --git a/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c b/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c index 427cf4cfb1..01b62e695d 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c @@ -238,6 +238,7 @@ xlvbd_alloc_gendisk(int minor, blkif_sector_t capacity, int vdevice, gd->first_minor = minor; gd->fops = &xlvbd_block_fops; gd->private_data = info; + gd->driverfs_dev = &(info->xbdev->dev); set_capacity(gd, capacity); if (xlvbd_init_blk_queue(gd, sector_size)) { diff --git a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c index f78cbad13e..09a622e7b1 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c @@ -88,11 +88,6 @@ #endif -#define NETIF_STATE_DISCONNECTED 0 -#define NETIF_STATE_CONNECTED 1 - -static unsigned int netif_state = NETIF_STATE_DISCONNECTED; - static void network_tx_buf_gc(struct net_device *dev); static void network_alloc_rx_buffers(struct net_device *dev); @@ -858,7 +853,7 @@ static int create_netdev(int handle, struct xenbus_device *dev, np->user_state = UST_CLOSED; np->handle = handle; np->xbdev = dev; - + spin_lock_init(&np->tx_lock); spin_lock_init(&np->rx_lock); @@ -902,7 +897,9 @@ static int create_netdev(int handle, struct xenbus_device *dev, netdev->features = NETIF_F_IP_CSUM; SET_ETHTOOL_OPS(netdev, &network_ethtool_ops); - + SET_MODULE_OWNER(netdev); + SET_NETDEV_DEV(netdev, &dev->dev); + if ((err = register_netdev(netdev)) != 0) { printk(KERN_WARNING "%s> register_netdev err=%d\n", __FUNCTION__, err); @@ -1176,8 +1173,6 @@ again: info->backend = backend; - netif_state = NETIF_STATE_CONNECTED; - return 0; abort_transaction: @@ -1276,30 +1271,7 @@ static struct xenbus_driver netfront = { static void __init init_net_xenbus(void) { - xenbus_register_device(&netfront); -} - -static int wait_for_netif(void) -{ - int err = 0; - int i; - - /* - * We should figure out how many and which devices we need to - * proceed and only wait for those. For now, continue once the - * first device is around. - */ - for ( i=0; netif_state != NETIF_STATE_CONNECTED && (i < 10*HZ); i++ ) - { - set_current_state(TASK_INTERRUPTIBLE); - schedule_timeout(1); - } - - if (netif_state != NETIF_STATE_CONNECTED) { - WPRINTK("Timeout connecting to device!\n"); - err = -ENOSYS; - } - return err; + xenbus_register_driver(&netfront); } static int __init netif_init(void) @@ -1318,8 +1290,6 @@ static int __init netif_init(void) init_net_xenbus(); - wait_for_netif(); - return err; } diff --git a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c index 8fda9cee72..b7e041acf4 100644 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c @@ -527,7 +527,7 @@ static struct xenbus_driver tpmfront = { static void __init init_tpm_xenbus(void) { - xenbus_register_device(&tpmfront); + xenbus_register_driver(&tpmfront); } diff --git a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c index 9c5116692b..baca05749d 100644 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c @@ -226,8 +226,8 @@ static int xenbus_dev_remove(struct device *_dev) return drv->remove(dev); } -static int xenbus_register_driver(struct xenbus_driver *drv, - struct xen_bus_type *bus) +static int xenbus_register_driver_common(struct xenbus_driver *drv, + struct xen_bus_type *bus) { int err; @@ -243,15 +243,15 @@ static int xenbus_register_driver(struct xenbus_driver *drv, return err; } -int xenbus_register_device(struct xenbus_driver *drv) +int xenbus_register_driver(struct xenbus_driver *drv) { - return xenbus_register_driver(drv, &xenbus_frontend); + return xenbus_register_driver_common(drv, &xenbus_frontend); } -EXPORT_SYMBOL(xenbus_register_device); +EXPORT_SYMBOL(xenbus_register_driver); int xenbus_register_backend(struct xenbus_driver *drv) { - return xenbus_register_driver(drv, &xenbus_backend); + return xenbus_register_driver_common(drv, &xenbus_backend); } void xenbus_unregister_driver(struct xenbus_driver *drv) @@ -260,6 +260,7 @@ void xenbus_unregister_driver(struct xenbus_driver *drv) driver_unregister(&drv->driver); up(&xenbus_lock); } +EXPORT_SYMBOL(xenbus_unregister_driver); struct xb_find_info { @@ -347,6 +348,18 @@ static char *kasprintf(const char *fmt, ...) return p; } +static ssize_t xendev_show_nodename(struct device *dev, char *buf) +{ + return sprintf(buf, "%s\n", to_xenbus_device(dev)->nodename); +} +DEVICE_ATTR(nodename, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_nodename, NULL); + +static ssize_t xendev_show_devtype(struct device *dev, char *buf) +{ + return sprintf(buf, "%s\n", to_xenbus_device(dev)->devicetype); +} +DEVICE_ATTR(devtype, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_devtype, NULL); + static int xenbus_probe_node(struct xen_bus_type *bus, const char *type, const char *nodename) @@ -383,6 +396,9 @@ static int xenbus_probe_node(struct xen_bus_type *bus, printk("XENBUS: Registering %s device %s: error %i\n", bus->bus.name, xendev->dev.bus_id, err); kfree(xendev); + } else { + device_create_file(&xendev->dev, &dev_attr_nodename); + device_create_file(&xendev->dev, &dev_attr_devtype); } return err; } diff --git a/linux-2.6-xen-sparse/include/asm-xen/xenbus.h b/linux-2.6-xen-sparse/include/asm-xen/xenbus.h index 57972a2588..924a752ac3 100644 --- a/linux-2.6-xen-sparse/include/asm-xen/xenbus.h +++ b/linux-2.6-xen-sparse/include/asm-xen/xenbus.h @@ -73,7 +73,7 @@ static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv) return container_of(drv, struct xenbus_driver, driver); } -int xenbus_register_device(struct xenbus_driver *drv); +int xenbus_register_driver(struct xenbus_driver *drv); int xenbus_register_backend(struct xenbus_driver *drv); void xenbus_unregister_driver(struct xenbus_driver *drv); -- 2.30.2